PluginProbe
Gutenify – Visual Site Builder Blocks & Starter Templates / 0.0.2
Gutenify – Visual Site Builder Blocks & Starter Templates v0.0.2
1.9.0 1.8.0 1.7.0 1.6.6 1.6.5 1.6.4 trunk 0.0.1 0.0.2 0.0.3 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 All 74 releases
gutenify / src / components / blocks / count-down / fontend copy.js

fontend copy.js in Gutenify – Visual Site Builder Blocks & Starter Templates 0.0.2, at src/components/blocks/count-down/fontend copy.js

166 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { render, Component } from '@wordpress/element';
2 import domReady from '@wordpress/dom-ready';
3
4 import { __ } from '@wordpress/i18n';
5
6 import { getTimeRemaining } from '../../../helpers/clock'
7
8 class App1 extends Component {
9 constructor(props) {
10 super(props);
11 // a place for the state
12 this.state = {
13 isTimerStart: false,
14 timerInterval: false,
15 timerDays: '00',
16 timerHour: '00',
17 timerMinute: '00',
18 timerSecond: '00',
19 };
20
21 this.initializeCountDown = this.initializeCountDown.bind(this);
22 }
23
24 initializeCountDown(dateTime) {
25 let $this = this;
26 function updateClock() {
27 var t = getTimeRemaining(dateTime);
28
29
30
31 $this.setState({
32 timerDays: t.days,
33 timerHour: ('0' + t.hours).slice(-2),
34 timerMinute: ('0' + t.minutes).slice(-2),
35 timerSecond: ('0' + t.seconds).slice(-2),
36 });
37
38
39
40 if (t.total <= 0 || isNaN(t.total)) {
41 $this.setState({
42 timerDays: '00',
43 timerHour: '00',
44 timerMinute: '00',
45 timerSecond: '00',
46 });
47 clearInterval(timeinterval);
48 }
49 }
50 updateClock();
51 var timeinterval = setInterval(updateClock, 1000);
52
53
54 this.setState({
55 timerInterval: timeinterval
56 });
57 }
58
59 getDefaults() {
60 const props = this.props;
61 const options = window[props.id];
62 const defaults = {
63 ...{
64 containerWidth: 100,
65 dateTime: new Date(),
66 containerWidthUnit: '%',
67 counterPosition: 'center',
68 showDays: true
69 }, ...options
70 }
71 return defaults;
72 }
73
74 componentDidMount() {
75 const defaults = this.getDefaults();
76 this.initializeCountDown(defaults.dateTime)
77 }
78
79 componentWillUnmount() {
80 clearInterval(this.state.timerInterval)
81 }
82
83 render() {
84 const defaults = this.getDefaults()
85 const {
86 dateTime,
87 showDays,
88 showHour,
89 showMinute,
90 showSecond,
91 showLabel,
92 customLabel,
93 customLabelDays,
94 customLabelHours,
95 customLabelMinutes,
96 customLabelSeconds
97 } = defaults;
98
99
100
101 const isShowDays = () => 'undefined' === typeof showDays || true === showDays ? true : false;
102 const isShowHour = () => 'undefined' === typeof showHour || true === showHour ? true : false;
103 const isShowMinute = () => 'undefined' === typeof showMinute || true === showMinute ? true : false;
104 const isShowSecond = () => 'undefined' === typeof showSecond || true === showSecond ? true : false;
105 const isShowLabel = () => 'undefined' === typeof showLabel || true === showLabel ? true : false;
106 const isCustomLabel = 'undefined' === typeof customLabel || false === customLabel ? false : true;
107
108
109 const getCustomLabelDays = () => {
110 let defaultLabel = 'Days';
111 let label = 'undefined' === typeof customLabelDays || '' === customLabelDays ? defaultLabel : customLabelDays;
112 label = isCustomLabel ? label : defaultLabel;
113 return label;
114 }
115
116 const getCustomLabelHours = () => {
117 let defaultLabel = 'Hours';
118 let label = 'undefined' === typeof customLabelHours || '' === customLabelHours ? defaultLabel : customLabelHours;
119 label = isCustomLabel ? label : defaultLabel;
120 return label;
121 }
122
123 const getCustomLabelMinutes = () => {
124 let defaultLabel = 'Minutes';
125 let label = 'undefined' === typeof customLabelMinutes || '' === customLabelMinutes ? defaultLabel : customLabelMinutes;
126 label = isCustomLabel ? label : defaultLabel;
127 return label;
128 }
129
130 const getCustomLabelSeconds = () => {
131 let defaultLabel = 'Seconds';
132 let label = 'undefined' === typeof customLabelSeconds || '' === customLabelSeconds ? defaultLabel : customLabelSeconds;
133 label = isCustomLabel ? label : defaultLabel;
134 return label;
135 }
136
137
138 return <div className="timer-count-down">
139 {isShowDays() && <><div className="time-part"><span className="days">{this.state.timerDays}</span>
140 {isShowLabel() && <div className="days-label smalltext">{getCustomLabelDays()}</div>}
141 </div></>}
142
143 {isShowHour() && <><div className="time-part"><span className="hours">{this.state.timerHour}</span>
144 {isShowLabel() && <div className="hours-label smalltext">{getCustomLabelHours()}</div>}
145 </div> </>}
146
147 {isShowMinute() && <><div className="time-part"><span className="minutes">{this.state.timerMinute}</span>
148 {isShowLabel() && <div className="minutes-label smalltext">{getCustomLabelMinutes()}</div>}
149 </div></>}
150
151 {isShowSecond() && <div className="time-part"><span className="seconds">{this.state.timerSecond}</span>
152 {isShowLabel() && <div className="seconds-label smalltext">{getCustomLabelSeconds()}</div>}
153 </div>}
154 </div>
155 }
156 }
157
158
159 domReady(function () {
160 //do something after DOM loads.
161 const allCountDown = document.getElementsByClassName('gutenify-count-down-wrapper');
162 for (let i = 0; i < allCountDown.length; i++) {
163 const id = allCountDown[i].getAttribute('id');
164 render(<App1 id={id} />, allCountDown[i]);
165 }
166 });